<template>
	<view class="container pbsafe_56">
		<u-sticky>
			<view class="ptb_14 plr_16 bc_fff">
				<uni-search-bar @confirm="getData(true)" placeholder="输入收货人或联系电话搜索" radius="20" :cancelButton="false"
					v-model="params.searchName" @clear="handleClear">
				</uni-search-bar>
			</view>
		</u-sticky>
		<view class="ptb_12 plr_16 bc_fff mt_8" v-for="item,index in dataList" :key="index">
			<view>
				物流名称：{{item.name||''}} {{item.mobile||''}}
			</view>
			<view class="mt_8 fx">
				<view class="fx_sh">收货地址：</view>
				<view>{{item.address||''}}</view>
			</view>
			<view class="fx aic jce mt_24">
				<button class="custom_btn default lh_28 width_80 br_18 fz_14"
					@click="handleDelete(item,index)">删除</button>
				<button class="custom_btn default lh_28 width_80 br_18 fz_14 ml_16"
					@click="handleUpdate(item)">编辑</button>
			</view>
		</view>
		<view class="pf b_0 l_0 r_0 pt_8 pbsafe_8 plr_16 bc_fff">
			<button class="custom_btn primary w100 lh_40 br_56 fz_14 fb" @click="handleAdd">添加新物流</button>
		</view>
	</view>
</template>

<script>
	import api from '@/service/config/api.js'
	import dataMixin from '@/mixins/data.js'
	export default {
		mixins: [dataMixin],
		data() {
			return {
				loading: false,
				dataList: [],
				deleteUrl: '/user/api/LogisticsManage',
				params: {
					searchName: ''
				},
			};
		},
		onShow() {
			this.getData()
		},
		methods: {
			getData() {
				this.$utils.loading()
				api.get('/user/api/LogisticsManage/list', {
					...this.params ? this.params : {}
				}).then(res => {
					this.dataList = res.data;
				})
			},
			handleAdd() {
				uni.navigateTo({
					url: '/pages/person/pages/logistics_add'
				})
			},
			handleClear() {
				const params = {
					...this.params
				}
				params.searchName = ''
				this.params = params
				this.getData()
			},
			handleDelete(item, index) {
				uni.showModal({
					content: '确认删除吗？',
					success: (res) => {
						if (res.confirm) {
							this.deleteData(item.id, index)
						}
					}
				})

			},
			handleUpdate(item) {
				uni.navigateTo({
					url: '/pages/person/pages/logistics_add?id=' + item.id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	/deep/.uni-searchbar {
		padding: 0;
	}

	/deep/.uni-searchbar__box {
		justify-content: flex-start;
	}
</style>